package com.grass.p019lv.service;

import android.app.PendingIntent;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import androidx.core.app.NotificationCompat;
import com.androidsa.bttsddka.R;
import com.grass.p019lv.activity.MineDownLoadVideoActivity;
import com.grass.p019lv.utils.NotificationChannelHelper;
import com.p020lv.downloadvideo.M3U8Downloader;
import com.p020lv.downloadvideo.OnM3U8DownloadListener;
import com.p020lv.downloadvideo.bean.M3U8Task;

/* renamed from: com.grass.lv.service.DownloadVideoService */
public class DownloadVideoService extends Service {
    public IBinder onBind(Intent intent) {
        return null;
    }

    public int onStartCommand(Intent intent, int i, int i2) {
        return 2;
    }

    public void onCreate() {
        super.onCreate();
        M3U8Downloader.getInstance().setOnM3U8DownloadListener(new OnM3U8DownloadListener() {
            /* class com.grass.p019lv.service.DownloadVideoService.C32241 */

            @Override // com.p020lv.downloadvideo.OnM3U8DownloadListener
            public void onDownloadSuccess(M3U8Task m3U8Task) {
                super.onDownloadSuccess(m3U8Task);
                DownloadVideoService.this.updateNotification(m3U8Task, "onDownloadSuccess");
            }

            @Override // com.p020lv.downloadvideo.OnM3U8DownloadListener
            public void onDownloadPause(M3U8Task m3U8Task) {
                super.onDownloadPause(m3U8Task);
                DownloadVideoService.this.updateNotification(m3U8Task, "onDownloadPause");
            }

            @Override // com.p020lv.downloadvideo.OnM3U8DownloadListener
            public void onDownloadPending(M3U8Task m3U8Task) {
                super.onDownloadPending(m3U8Task);
                DownloadVideoService.this.updateNotification(m3U8Task, "onDownloadPending");
            }

            @Override // com.p020lv.downloadvideo.OnM3U8DownloadListener
            public void onDownloadProgress(M3U8Task m3U8Task) {
                super.onDownloadProgress(m3U8Task);
                DownloadVideoService.this.updateNotification(m3U8Task, "onDownloadProgress");
            }

            @Override // com.p020lv.downloadvideo.OnM3U8DownloadListener
            public void onDownloadPrepare(M3U8Task m3U8Task) {
                super.onDownloadPrepare(m3U8Task);
                DownloadVideoService.this.updateNotification(m3U8Task, "onDownloadPrepare");
            }

            @Override // com.p020lv.downloadvideo.OnM3U8DownloadListener
            public void onDownloadError(M3U8Task m3U8Task, Throwable th) {
                super.onDownloadError(m3U8Task, th);
                DownloadVideoService.this.updateNotification(m3U8Task, "onDownloadError");
            }
        });
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void updateNotification(M3U8Task m3U8Task, String str) {
        if ("onDownloadSuccess".equals(str)) {
            stopForeground(true);
        } else {
            startNotification(m3U8Task, str);
        }
    }

    private void startNotification(M3U8Task m3U8Task, String str) {
        NotificationCompat.Builder builder = new NotificationCompat.Builder(this, NotificationChannelHelper.CHANNEL_ID_FOR_DOWNLOAD);
        builder.setOnlyAlertOnce(true);
        builder.setSmallIcon(R.drawable.ic_logo);
        if ("onDownloadPause".equals(str)) {
            builder.setContentTitle("下载暂停");
        } else if ("onDownloadError".equals(str)) {
            builder.setContentTitle("下载出错");
        } else {
            builder.setContentTitle("正在下载");
            builder.setContentText(m3U8Task.getFormatSpeed());
        }
        builder.setContentIntent(PendingIntent.getActivity(this, 1, new Intent(this, MineDownLoadVideoActivity.class), 134217728));
        startForeground(1, builder.build());
    }

    public void onDestroy() {
        stopForeground(true);
        super.onDestroy();
    }
}
